<template>
    <div class="association-member-hint-text">
        <div class="hint-text-one">
            <!-- 1分钟<a class="btn" @click="enterBus">创建业务名片</a>发布您的供应和需求信息！ -->
            本次列表更新时间:{{updataTimeText}}
        </div>
        <div>
            <a class="btn" @click="enterBus">1分钟发布</a>供应和需求！
            如未显示 <a class="btn" @click="clickCheckReason">查看原因</a>
        </div>

        <!-- 未设置业务名片弹窗 -->
		<need-set-bus-window
		:textOne="needSetBus.message"
		:textSecond="needSetBus.messageTwo"
		:closeBtnText="needSetBus.closeBtnText"
		:sureBtnText="needSetBus.sureBtnText"
		:isShow="showWindow === 'needSetBus'"
		:overlayShow="overlayShow"
		@hideOverlay="hideOverlay"
		></need-set-bus-window>

		<!-- 未登录弹窗 -->
		<need-login-window 
		@closeNeedLooginWindow="closeWindow" 
		:isShow="showWindow === 'needLogin'">
		</need-login-window>
		
		<!-- 绑定微信弹窗 -->
		<bind-wechat-window
		@closeBindWechatWindow="closeWindow" 
		:isShow="showWindow === 'bindWechat'"
        :message="'您尚未绑定微信！\n请30秒绑定微信，将您的供应和需求信息展示到微信群业务信息列表！'"
		/>
        <van-overlay :show="overlayShow" @click="hideOverlay" duration="0" />

        <!-- 更新业务列表弹窗 -->
        <updata-list-window
        @updataList="updataList"
        @showService="showService"
		:isShow="showWindow === 'updataList'"
        @closeUpdataListWindow="closeWindow"
        ></updata-list-window>

        <!-- 已更新弹窗 -->
        <already-updata-window 
        @showBindWechat="showBindWechat" 
        @closeWindow="closeWindow" 
        :isShow="showWindow === 'alreadyUpData'"
        ></already-updata-window>
    </div>
</template>

<script>
// 自定义方法
import { enterUserSet } from '_projectFn/page'
import { isLoginChose } from '_projectFn/login'
import { getCookie } from '_commonFn/cookie'
import { loadingVantToa, clearVantToa } from "_projectFn/prompt"
import { updateWechatGroInfoList, isLogined } from '_network/request'
import { showService } from '_projectFn/sundry'

// UI组件
import { Overlay } from "vant"

// 自定义组件
import NeedSetBusWindow from "_components/project/ShowWindow/NeedSetBusWindow"
import NeedLoginWindow from "_components/project/ShowWindow/NeedLoginWindow"
import BindWechatWindow from "_components/project/ShowWindow/BindWechatWindow"
import UpdataListWindow from "_components/project/MembelListWechat/UpdataListWindow"
import AlreadyUpdataWindow from "_components/project/MembelListWechat/AlreadyUpDataWindow"

import Vue from 'vue'

Vue.use(Overlay)

export default {
    name: 'TopExplain',
    props: {
        isBindWechat: {
            default: 0
        },
        pageBasicData: {
            type: Object,
            default: {}
        },
        updataTimeText: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            overlayShow: false,
            showWindow: '',
            needSetBus: {
                message: '您尚未创建业务名片！',
                messageTwo: '请1分钟创建业务名片，发布您的供应和需求信息！',
                closeBtnText: '关闭',
                sureBtnText: '创建业务名片',
            }
        }
    },
    methods: {
        // 进入设置业务名片
        enterBus() {
            const url = process.env.IS_L0CAL ? location.href.split('#')[0] : `../user-accountManagement.html?option=business`
            enterUserSet('business', url)
        },
        // 点击查看原因
        clickCheckReason() {
            const that = this
            isLogined({
                callback(isLogin) {
                    if (isLogin) {
                        // console.log('that.pageBasic', that.pageBasic)
                        if (that.pageBasic.isSeted) {
                            clearVantToa()
                            that.checkReason()
                        } else {
                            loadingVantToa({})
                            setTimeout(() => {
                                that.clickCheckReason()
                            }, 10)
                        }
                    } else { // 显示未登录弹窗
                        that.showWindow = 'needLogin'
                        that.showOverlay()
                    }
                }
            })
        },
        // 执行查看原因
        checkReason(data = this.pageBasic) {
            // console.log('this.pageBasic', this.pageBasic)
            if (data.isSetBus === 0) {
                this.showWindow = 'needSetBus'
                this.showOverlay()
            } else if (data.isBindWechat === 0) {
                this.showBindWechat()
            } else if (data.isBeForeUpdataMyInfo) {
                this.showWindow = 'updataList'
            } else {
                this.showWindow = 'alreadyUpData'
            }
        },
        // 隐藏遮罩层
        hideOverlay() {
            this.showWindow = ''
            this.overlayShow = false
        },
        // 显示遮罩层
        showOverlay() {
            this.overlayShow = true
        },
        // 点击更新列表
        updataList() {
            console.log('updataList')
            if (isLoginChose()) {
                const that = this
                updateWechatGroInfoList({
                    groupWxId: this.$route.query.wecGroId,
                    kfWxId: this.$route.query.serWecId,
                    // callback() {
                    //     that.$emit('updataList')
                    // }
                })
            }
        },
        // 点击显示客服
        showService() {
            showService()
        },
        // 关闭弹窗事件
        closeWindow() {
            this.hideOverlay()
        },
        showBindWechat() {
            this.showWindow = 'bindWechat'
        }
    },
    computed: {
        pageBasic() {
            return this.pageBasicData
        }
    },
    // mounted() {
    //     console.log('this.$route', this.$route.wecGroId)
    // },
    components: {
        NeedSetBusWindow,
		NeedLoginWindow,
        BindWechatWindow,
        UpdataListWindow,
        AlreadyUpdataWindow,
    }
}
</script>

<style lang="scss" scoped>
.association-member-hint-text {
    padding: 10px 15px;
    background: #465992;
    color: white;
    line-height: 20px;

    .hint-text-one {
        font-size: 12px;
    }

    .color-black {
        color: black;
    }

    .btn {
        text-decoration: underline;
        color: #dbd824;
        margin: 0 2px;
    }
}
</style>